#!/bin/bash

echo "🚀 启动 DataWorks 数据中台平台..."

# 检查 Docker 是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ Docker 未运行，请先启动 Docker"
    exit 1
fi

# 创建必要的目录
echo "📁 创建必要的目录..."
mkdir -p logs uploads airflow/logs airflow/dags airflow/plugins

# 设置权限
chmod +x docker/airflow-entrypoint.sh

# 构建并启动服务
echo "🔨 构建并启动服务..."
docker-compose up --build -d

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 30

# 检查服务状态
echo "🔍 检查服务状态..."
docker-compose ps

echo ""
echo "✅ 服务启动完成！"
echo ""
echo "🌐 访问地址："
echo "  - API 文档: http://localhost:8000/docs"
echo "  - Airflow: http://localhost:8080 (admin/admin123)"
echo "  - 健康检查: http://localhost:8000/health"
echo ""
echo "📝 查看日志："
echo "  docker-compose logs -f [service_name]"
echo ""
echo "🛑 停止服务："
echo "  docker-compose down" 